fix(databricks): ensure parallel tool image responses don't interleave tool results#9241
Conversation
…e tool results When multiple parallel tool calls each return images, format_tool_response was emitting user-role image messages between tool-role result messages. Claude's API requires all tool_result blocks to be consecutive after tool_use blocks. Fix by deferring image user-messages until all tool result messages for a given goose Message have been emitted. Fixes aaif-goose#7449 Signed-off-by: Steve Marshall <steve.marshall@fasthosts.com>
- Merge with latest main (formatting updates from edition bump) - Trim redundant comments in code and tests to one-liners Signed-off-by: Douwe Osinga <douwe@squareup.com>
DOsinga
left a comment
There was a problem hiding this comment.
Clean fix for #7449. The deferred-image-messages approach is correct and minimal. I merged main, ran cargo fmt (Rust edition bump changed import ordering), and trimmed the verbose comments down to one-liners. Tests pass, clippy clean.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 874a70b880
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if msg.role == "user" { | ||
| pending_image_messages.push(msg); |
There was a problem hiding this comment.
Preserve image-to-tool association when reordering responses
Deferring every user image message until after all tool responses breaks the implicit pairing between a tool result and its image payload. In mixed parallel results (e.g., tool A has an image, tool B is text-only), the image from A is emitted after B, and these image messages carry no tool_call_id, so the model can misattribute which tool produced which image. This is a behavior regression from the prior adjacent ordering and can lead to incorrect reasoning about tool outputs.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
I've prepared a pull request into this branch so the approach I took can be reviewed first msteve123#1
@DOsinga Did you want to take a look?
* main: (38 commits) [Prompt injection mitigation] Update pattern-based detection to reduce FPs (#9350) feat: add Harbor eval runner (#9138) chore(release): bump version to 1.35.0 (minor) (#9150) Include request URL in provider error messages (#9232) fix(databricks): ensure parallel tool image responses don't interleave tool results (#9241) Surface resolved Databricks model metadata (#9206) Add unified thinking effort control across all providers (#9242) Add Linux desktop Vulkan packages (#9323) chore: update canonical model registry (#9331) feat: slash commands (built-in, skill, recipe) in acp server (#9238) feat: add /goal command for agent self-evaluation before finishing (#9069) Feat/summon subagent instructions (#9325) feat: open-plugins generalization + skills (#9112) feat(hooks): PreToolUse denial (#9304) Add support for optional api_key configuration for declarative openai-engine providers (#9202) fix(cli): use plain '> ' prompt instead of goose emoji (#9305) flag for login shell PATH (#9313) Remove popular chat topics from new chat screen (#9307) fix: stop killing goosed when a window closes (#9302) Remove vendored Windows binaries (#9318) ...
Fixes #7449
Collects all tool-role messages first and appends user-role image messages after, so the API sees consecutive tool results followed by user image messages. This prevents Claude's API from rejecting requests when multiple parallel tool calls return images.